﻿#pragma once

#include <QDateTime>
#include <QString>
#include <QThread>

class SoftEtherClient : public QThread {
    Q_OBJECT
public:
    SoftEtherClient();

signals:
    void stateChanged(QString msg);
    void loginFinish(bool loginOK);
    void logoutOK();

public:
    void run() override;
    bool clean();
    QVariantMap getVPNStatus(QString vlanName);

    void connectVpn(QString serverAddress, QString hubName, QString username, QString password, QString staticIP);

    /// 是否在线
    bool isOnline();

    /// 获取在线时长，单位秒
    int getOnlineTime();

    QString getVpnIP();

    QDateTime getConnectTime() const;

protected:
    bool startClient();
    bool createNic(QString vlanName);
    bool enableNic(QString vlanName);
    bool createAccount(QString vlanName, QString serverAddress, QString hubName, QString username);
    bool setPassword(QString vlanName, QString password);
    bool disableRemote();
    bool enableKeeplive();
    bool enableAccountStartup(QString vlanName);
    bool enableAccountRetry(QString vlanName);
    bool setIP(QString vlanName, QString staticIP);
    bool setTcp(QString vlanName);
    bool connectAccount(QString vlanName);

protected:
    bool stopClient();
    bool disconnectVpn(QString vlanName);
    bool deleteAccount(QString vlanName);
    bool disableNic(QString vlanName);
    bool deleteNic(QString vlanName);

protected:
    bool setLinkUp(QString vlanName);
    bool deleteLink(QString vlanName);

private:
    bool runSoftEtherCmd(QString stepTitle, QStringList cmd);

private:
    QString m_vpncmdPath;
    QString m_vpnclientPath;

private:
    QString vlanName;
    QString serverAddress;
    QString hubName;
    QString username;
    QString password;
    QString staticIP;

private:
    QDateTime m_connectTime; /// 连接成功的时间
    bool m_connectOK;        /// 是否连接成功
};
